﻿namespace ShellNavigator.Client.Utils
{
  #region

  using System.Collections.Generic;

  #endregion

  public static class MaskHelper
  {
    #region Constants and Fields

    private const string ElseSeparator = "<>";

    private const char OrSeparator = '|';

    #endregion

    #region Public Methods

    public static void ParseMask(string filemask, List<string> includeList, List<string> excludeList)
    {
      if (string.IsNullOrEmpty(filemask))
      {
        includeList.Add("*.*");
        return;
      }

      var elsePosition = filemask.IndexOf(ElseSeparator);

      if (elsePosition == -1)
      {
        includeList.AddRange(filemask.Split(OrSeparator));
      }
      else
      {
        var includePart = filemask.Substring(0, elsePosition);
        var excludePart = filemask.Substring(elsePosition + ElseSeparator.Length);

        includeList.AddRange(includePart.Split(OrSeparator));
        excludeList.AddRange(excludePart.Split(OrSeparator));
      }
    }

    #endregion
  }
}